package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ZcMachinery;
import com.ruoyi.system.service.IZcMachineryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 机械设备类Controller
 * 
 * @author ruoyi
 * @date 2023-06-26
 */
@Controller
@RequestMapping("/system/machinery")
public class ZcMachineryController extends BaseController
{
    private String prefix = "system/machinery";

    @Autowired
    private IZcMachineryService zcMachineryService;

    @RequiresPermissions("system:machinery:view")
    @GetMapping()
    public String machinery()
    {
        return prefix + "/machinery";
    }

    /**
     * 查询机械设备类列表
     */
    @RequiresPermissions("system:machinery:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZcMachinery zcMachinery)
    {
        startPage();
        List<ZcMachinery> list = zcMachineryService.selectZcMachineryList(zcMachinery);
        return getDataTable(list);
    }

    /**
     * 导出机械设备类列表
     */
    @RequiresPermissions("system:machinery:export")
    @Log(title = "机械设备类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZcMachinery zcMachinery)
    {
        List<ZcMachinery> list = zcMachineryService.selectZcMachineryList(zcMachinery);
        ExcelUtil<ZcMachinery> util = new ExcelUtil<ZcMachinery>(ZcMachinery.class);
        return util.exportExcel(list, "机械设备类数据");
    }

    /**
     * 新增机械设备类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存机械设备类
     */
    @RequiresPermissions("system:machinery:add")
    @Log(title = "机械设备类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZcMachinery zcMachinery)
    {
        return toAjax(zcMachineryService.insertZcMachinery(zcMachinery));
    }

    /**
     * 修改机械设备类
     */
    @RequiresPermissions("system:machinery:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZcMachinery zcMachinery = zcMachineryService.selectZcMachineryById(id);
        mmap.put("zcMachinery", zcMachinery);
        return prefix + "/edit";
    }

    /**
     * 修改保存机械设备类
     */
    @RequiresPermissions("system:machinery:edit")
    @Log(title = "机械设备类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZcMachinery zcMachinery)
    {
        return toAjax(zcMachineryService.updateZcMachinery(zcMachinery));
    }

    /**
     * 删除机械设备类
     */
    @RequiresPermissions("system:machinery:remove")
    @Log(title = "机械设备类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zcMachineryService.deleteZcMachineryByIds(ids));
    }
}
